package com.example.service.serviceImple;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.example.pojo.User;
import com.example.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TokenServiceImpl implements TokenService {

    @Override
    public String getToken(User userDo) {
        Date start = new Date();
        long currentTime = System.currentTimeMillis() + 60 * 60 * 2000;//两小时有效时间
        Date end = new Date(currentTime);
        String token="";
        token= JWT.create().withAudience(userDo.getUserId()).withIssuedAt(start).withExpiresAt(end)
                .sign(Algorithm.HMAC256(userDo.getPassword()));
            return token;
    }

}
